class Solution {
public:
    int tribonacci(int n) {
        int T0=0,T1=0,T2=1,T3=1;
        if(n==0) return 0;
        if(n==1 || n==2) return 1;
        for(int i=2;i<n;i++){  
            T0=T1;
            T1=T2;
            T2=T3;
            T3=T2+T1+T0;
        }
        return T3;
    }
};